import MD5 from "md5";

function buildParams(jsonData) {
  const sortedKey = Object.keys(jsonData).sort();

  let ticketStr = "";
  for (let i = 0; i < sortedKey.length; i++) {
    const key = sortedKey[i];
    ticketStr = ticketStr.length > 0 ? ticketStr + "&" : "";
    ticketStr = ticketStr + key + "=" + jsonData[key];
  }

  return ticketStr + "xu7t6j8vmso3lrbcwz0hind5p14qfyge";
}

export function encryParams(params) {
  const ticket = MD5(buildParams(params));
  params["ticket"] = ticket;
  return params;
}
